#!/usr/bin/env python
# -*-coding:UTF-8 -*-
'''
@Project ：19-xpath站长素材.py
@File：30-异步协程爬虫.py
@Author ：文非
@Date：2021/3/1519:43
@Require：
'''
import aiohttp
import asyncio

async def get_response(session,url):
    print("发送请求：", url)
    async with session.get(url, verify_ssl = False) as response:
        text = await response.text()
        print("得到结果：", url, len(text))
        return text

async def main():
    async with aiohttp.ClientSession()as session:
        url_list = [
            "https://sougou.com",
            "https://baidu.com",
            "https://weibo.com"
        ]
        tasks = [asyncio.create_task(get_response(session,url))for url in url_list]

        done,pending = await asyncio.wait(tasks)


if __name__=="__main__":
    asyncio.run(main())